<template>
	<view class="container">
		<!-- #ifdef MP-WEIXIN -->
		<button class="btn" open-type="getPhoneNumber" @getphonenumber="getPhone">手机号快捷登录</button>
		<!-- #endif -->
		<!-- #ifdef H5 -->
		  <input class="uni-input" focus placeholder="密码" />
		  <button type="default" @click="goAuth">密码登录</button>
		<!-- #endif -->
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				detail:{
					code: "a60231dca8b0f7d87a9cd635ca9294915af768486c183ac4f7aba8bf59c16883",
					encryptedData: "9YFd7xdQj8Qb/t5z6H8tv30SAL77+X3Ca7w9LxQXDEocvTDB4UBf+/65yVzvONfcsLT38kv+MgmToNfmSxCWbATO/IlzVu6v8WTDXjlUOaP4rcLRtRuIrzKnr/Cm51bmRsAyuJ6pfbN264BdkQ6vk4hRddJpTryjuf4b3wpazyPwquWL7pcn/3wfsgT5p0hkT0IrUZr2r1RXOfdDLQBGkA==",
					errMsg: "getPhoneNumber:ok",
					iv: "aKjQH0S+CUHwu8WubjC6NA=="
				},
				code:""  // 临时登录票据-只能使用一次
			};
		},
		onShow() {
			
			// 获取服务商
			uni.getProvider({
				service:'oauth',  // oauth:授权登录 share:分享 payment：支付
				success(res) {
					if(res.provider.includes("weixin")){
						uni.login({
							provider:"weixin",  // 使用微信登录
							success(res) {
								this.code =res.code
								
								console.log(res,this.code,'res1243')
							}
						})
					}
				}
			})
			
		},
		methods: {
			getPhone(data) {
				const {errMsg} =data.detail
				if(errMsg==="getPhoneNumber:ok"){
					console.log('获取手机号成功')
					uni.showToast({
					  title:"登录成功"
					})
					setTimeout(()=>{
						uni.switchTab({
							url:'/pages/home/home'
						})
					},2000)
				}
			},
			goAuth(){
				// web平台不支持
				 uni.login({
					provider:'weixin',
					success: (res) => {
						console.log(res,'h5授权登录')
					}
				})
				console.log('授权登录')
			}
		},
	}
</script>

<style lang="scss" scoped>
.container{
	display: flex;
    align-items: center;
	height:100vh;
	.btn{
		width:580rpx;
		background-color:green;
		color:#fff;
	}
}
</style>
